﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InstituteManager.Bussiness;
using InstituteManager.Data;
using System.Web.Security;


namespace InstituteManager.adm
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {   
            string md5Password = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "MD5");
            int permission = 0;
            if (StaffBL.checkLogin(txtUsername.Text, md5Password, ref permission))
            {
                Session["Username"] = txtUsername.Text;
                Session["Permission"] = permission.ToString();
                if (Request.QueryString["redirect"] != null)
                    Response.Redirect(Request.QueryString["redirect"]);
                else
                    Response.Redirect("default.aspx");
            }
            else
                if (StudentBL.checkLogin(txtUsername.Text, md5Password))
                {
                    Session["Username"] = txtUsername.Text;
                    Session["Permission"] = 0;
                    if (Request.QueryString["redirect"] != null)
                        Response.Redirect(Request.QueryString["redirect"]);
                    else
                        Response.Redirect("default.aspx");
                }
                else
                    lblError.Visible = true;
        }

    }
}